class Solution(object):
    def sumEvenAfterQueries(self, nums, queries):
        even = 0
        odd = 0
        for num in nums:
            if num % 2 == 0:
                even += num
            else:
                odd += num
        out = []
        for q in queries:
            if q[0] % 2 == 0:
                if nums[q[1]] % 2 == 0:
                    even += q[0]
                else:
                    odd += q[0]
            else:
                if nums[q[1]] % 2 == 0:
                    odd += nums[q[1]] + q[0]
                    even -= nums[q[1]]
                else:
                    even += nums[q[1]] + q[0]
                    odd -= nums[q[1]]
            nums[q[1]] += q[0]
            out.append(even)
        return out



data = Solution()
nums = [1, 2, 3, 4]
queries = [[1, 0], [-3, 1], [-4, 0], [2, 3]]
print(data.sumEvenAfterQueries(nums, queries))
